home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 August (Alt) / CHIP 2005-08.1.iso / program / guvenlik / syslinux-3.07.exe / memdisk / e820test.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-14  |  2.2 KB  |  90 lines

  1. #ident "$Id: e820test.c,v 1.8 2004/12/14 22:46:25 hpa Exp $"
  2. /* ----------------------------------------------------------------------- *
  3.  *   
  4.  *   Copyright 2001-2003 H. Peter Anvin - All Rights Reserved
  5.  *
  6.  *   This program is free software; you can redistribute it and/or modify
  7.  *   it under the terms of the GNU General Public License as published by
  8.  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
  9.  *   Boston MA 02111-1307, USA; either version 2 of the License, or
  10.  *   (at your option) any later version; incorporated herein by reference.
  11.  *
  12.  * ----------------------------------------------------------------------- */
  13.  
  14. /*
  15.  * e820hack.c
  16.  *
  17.  * Test of INT 15:E820 canonicalization/manipulation routine
  18.  */
  19.  
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <inttypes.h>
  24. #include "e820.h"
  25.  
  26. void *sys_bounce;        /* Dummy */
  27.  
  28. extern void parse_mem(void);
  29. extern uint32_t dos_mem, low_mem, high_mem;
  30.  
  31. void __attribute__((noreturn)) die(void)
  32. {
  33.   abort();
  34. }
  35.  
  36. void printranges(void) {
  37.   int i;
  38.  
  39.   for ( i = 0 ; i < nranges ; i++ ) {
  40.     printf("%016llx %016llx %d\n",
  41.        ranges[i].start,
  42.        ranges[i+1].start - ranges[i].start,
  43.        ranges[i].type);
  44.   }
  45. }
  46.  
  47. int main(void)
  48. {
  49.   uint64_t start, len;
  50.   uint32_t type;
  51.   char line[BUFSIZ], *p;
  52.  
  53.   e820map_init();
  54.   printranges();
  55.  
  56.   while ( fgets(line, BUFSIZ, stdin) ) {
  57.     p = strchr(line, ':');
  58.     p = p ? p+1 : line;
  59.     if ( sscanf(p, " %llx %llx %d", &start, &len, &type) == 3 ) {
  60.       putchar('\n'); 
  61.       printf("%016llx %016llx %d <-\n", start, len, type);
  62.       putchar('\n'); 
  63.       insertrange(start, len, type);
  64.       printranges(); 
  65.     }
  66.   }
  67.  
  68.   parse_mem();
  69.  
  70.   putchar('\n');
  71.   printf("DOS  mem = %#10x (%u K)\n", dos_mem, dos_mem >> 10);
  72.   printf("Low  mem = %#10x (%u K)\n", low_mem, low_mem >> 10);
  73.   printf("High mem = %#10x (%u K)\n", high_mem, high_mem >> 10);
  74.   putchar('\n');
  75.  
  76.   /* Now, steal a chunk (2K) of DOS memory and make sure it registered OK */
  77.   insertrange(dos_mem-2048, 2048, 2); /* Type 2 = reserved */
  78.   
  79.   printranges();
  80.   parse_mem();
  81.  
  82.   putchar('\n');
  83.   printf("DOS  mem = %#10x (%u K)\n", dos_mem, dos_mem >> 10);
  84.   printf("Low  mem = %#10x (%u K)\n", low_mem, low_mem >> 10);
  85.   printf("High mem = %#10x (%u K)\n", high_mem, high_mem >> 10);
  86.   putchar('\n');
  87.  
  88.   return 0;
  89. }
  90.